package com.mxy.myapplication2.java;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.widget.NestedScrollView;
import android.util.AttributeSet;
import android.view.MotionEvent;

public class InterceptNestedScrollView extends NestedScrollView {

    /**
     * 是否拦截触摸事件
     */
    private boolean interceptTouchEvent = false;

    public boolean isInterceptTouchEvent() {
        return interceptTouchEvent;
    }

    public void setInterceptTouchEvent(boolean interceptTouchEvent) {
        this.interceptTouchEvent = interceptTouchEvent;
    }

    public InterceptNestedScrollView(@NonNull Context context) {
        super(context);
    }

    public InterceptNestedScrollView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public InterceptNestedScrollView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }


    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        if (isInterceptTouchEvent()) {
            return true;
        } else {
            return super.onInterceptTouchEvent(ev);
        }
    }
}